package com.idconfirmsystem.activity;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.idconfirmsystem.R;
import com.idconfirmsystem.model.UserBean;

public class IdConfirmActivity extends Activity {
	String type=UserBean.getInstance().getType();
	// 运行时临时变量
	private RuntimeObject ru = new RuntimeObject();

	public class RuntimeObject {
	}

	// 配套Handler
	// private Handler handler = new MainHandler(MainActivity.this);

	// 布局元素
	private Element el = new Element();

	public class Element {
		Button idConfirm;
		EditText idConfirmEdit;
		LinearLayout cutomInfo;
		Button idSure;
		LinearLayout lconfirmInput;
		LinearLayout lcar;
		LinearLayout lclert;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(type=="SY"){
			setContentView(R.layout.activity_id_confirm);
		}else {
			setContentView(R.layout.activity_id_confirm_kh);
		}

		ActionBar ab = getActionBar();
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setHomeButtonEnabled(true);

		initView();
	}

	public void initView() {
		el.lcar=(LinearLayout) findViewById(R.id.ll_car);
		el.lclert=(LinearLayout) findViewById(R.id.ll_clerk);
		el.lconfirmInput=(LinearLayout) findViewById(R.id.llConfirmInput);
		el.idConfirmEdit = (EditText) findViewById(R.id.id_confirm_edit);
		el.cutomInfo = (LinearLayout) findViewById(R.id.custom_info);
		el.idConfirm = (Button) findViewById(R.id.id_confirm);
		el.idConfirm.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String password = el.idConfirmEdit.getText().toString();
				if ("123456".equals(password)) {
					Builder dlg = new Builder(IdConfirmActivity.this);
					dlg.setTitle("提示");
					dlg.setMessage("身份验证成功！");
					dlg.show();
					el.idConfirm.setVisibility(View.GONE);
					el.lconfirmInput.setVisibility(View.GONE);
//					el.cutomInfo.setVisibility(View.VISIBLE);
					checkSuccessVisible();
				} else {
					Builder dlg = new Builder(IdConfirmActivity.this);
					dlg.setTitle("提示");
					dlg.setMessage("身份验证失败！请重新输入");
					dlg.show();
				}

			}
		});
		el.idSure=(Button) findViewById(R.id.id_sure);
		el.idSure.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), "确认成功", Toast.LENGTH_SHORT).show();
				finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.id_confirm, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if (item.getItemId() == android.R.id.home) {
			finish();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	public void checkSuccessVisible(){
		if(type=="KH"){
			el.cutomInfo.setVisibility(View.VISIBLE);
			el.lcar.setVisibility(View.VISIBLE);
			el.lclert.setVisibility(View.VISIBLE);
		}else {
			el.cutomInfo.setVisibility(View.VISIBLE);
		}
		el.idSure.setVisibility(View.VISIBLE);
	}
}
